package com.example.sxt_practise.money;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author gaofeng
 * date 2021年09月08日 21:16
 */
public class Test {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(9000);
        Socket socket = serverSocket.accept();
        InputStream inputStream = ((Socket) socket).getInputStream();
        FileOutputStream fileOutputStream = new FileOutputStream(new File("receive.jpeg"));
        byte[] bytes = new byte[1024];
        int len;
        while ((len=inputStream.read(bytes))!=-1) {
            fileOutputStream.write(bytes,0,len);
        }
        fileOutputStream.close();
        inputStream.close();
        socket.close();
        serverSocket.close();;
    }
}
